import request from '@/api/axios';
import { baseUrl } from '@/config/env';

export const loginByUsername = (tenantId, username, password, type) => request({
  url: '/api/blade-auth/oauth/token',
  method: 'post',
  headers: {
    'Tenant-Id': tenantId
  },
  params: {
    tenantId,
    username,
    password,
    grant_type: "password",
    scope: "all",
    type
  }
})

export const refreshToken = (refresh_token, tenantId) => request({
  url: '/api/blade-auth/oauth/token',
  method: 'post',
  headers: {
    'Tenant-Id': tenantId
  },
  params: {
    tenantId,
    refresh_token,
    grant_type: "refresh_token",
    scope: "all",
  }
})

export const getButtons = () => request({
  url: '/api/blade-system/menu/buttons',
  method: 'get'
});

export const getUserInfo = () => request({
  url: baseUrl + '/user/getUserInfo',
  method: 'get'
});

export const sendLogs = (list) => request({
  url: baseUrl + '/user/logout',
  method: 'post',
  data: list
})

// 原来的退出方法
// export const logout = () => request({
//   url: baseUrl + '/user/logout',
//   method: 'get'
// })

// 平台自定义的退出方法
export const logout = (userInfo) => request({
  url: '/api/blade-auth/token/logout',
  method: 'POST',
  data: {
    ...userInfo
  }
})
